<?php 


use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface {


	/**
	 * The database table used by the model.
	 *
	 * @var string
	 */
	protected $table = 'users';
	protected $primaryKey = 'id';
	const CREATED_AT = 'created_time';
	const UPDATED_AT = 'updated_time';
// //Login
// 	//Check login thuc hien nhiem vu kiem tra client muon dang nhap = email hay username

// 	public static function check_login($user_input,$password){
// 		$array1=array('user_input'=>$user_input);
// 		$rules=array('user_input'=>'email');
// 		if(Validator::make($array1,$rules)->fails())
// 			$check=User::where('username','=',$user_input)->where('password','=',$password)->count();
// 		else
// 			$check=User::where('email','=',$user_input)->where('password','=',$password)->count();
// 		if($check>0)
// 			return true;
// 		else return false;
// 	}
	
//Sign Up
	//Check username thuc hien kiem tra username da ton tai hay chua
	public static function check_username($username){
		if(User::where('username','=',$username)->count()>0)
			return false;
		else return true;
	}
	//Check email thuc hien kiem tra username da ton tai hay chua
	public static function check_email($email){
		if(User::where('email','=',$email)->count()>0)
			return false;
		else return true;
	}

	
	/**
	 * The attributes excluded from the model's JSON form.
	 *
	 * @var array
	 */
	protected $hidden = array('password', 'remember_token');

	public function userInformation(){
		return $this->hasOne('UserInformation','id','id');
	}

	public function rates(){
		return $this->hasMany('UserRatePlace','user_id');
	}

	public function permissions(){
		return $this->hasMany('UserHasPlace', 'user_id');
	}

	public function ID(){
		return $this->belongsTo('ID');
	}
	/**
	 * Get the unique identifier for the user.
	 *
	 * @return mixed
	 */
	public function getAuthIdentifier()
	{
	    return $this->getKey();
	}

	/**
	 * Get the password for the user.
	 *
	 * @return string
	 */
	public function getAuthPassword()
	{
	    return $this->password;
	}

	/**
	 * Get the e-mail address where password reminders are sent.
	 *
	 * @return string
	 */
	public function getReminderEmail()
	{
	    return $this->email;
	}
	public function getRememberToken()
	{
	    return $this->remember_token;
	}

	public function setRememberToken($value)
	{
	    $this->remember_token = $value;
	}

	public function getRememberTokenName()
	{
	    return 'remember_token';
	}

}
